import type { TableColumnInstance } from 'element-plus'
import type { VxeColumnProps } from 'vxe-table'

import TableView from './src/el-table-vue.vue'
import VxeTableVue from './src/vxe-table-vue.vue'

const tableUtils = {
  setChecked: (list: IVxueColumnConfig<any>[]) => {
    list.forEach(col => (col.show = true))
  }
}

export interface IKey {
  [key: string]: any
}

interface IPropsFnObject {
  /**映射列显示，不同场景下显示的列不一样 */
  mapColumn?: (list: any[]) => any[]
  /**禁止行修改 */
  disableUpdate?: (data: any) => boolean
  /**禁止行删除 */
  disableRowDel?: (data: any) => boolean
}

type PartialColumn = Partial<TableColumnInstance>
type PartialVxeColumn = Partial<VxeColumnProps>

/**
 * el-table表格列配置
 */
interface IColumnConfig<T = IKey> extends Omit<PartialColumn, 'prop'> {
  prop?: keyof T
  slot?: string
}

/**
 * vxe-table表格列配置
 */
interface IVxueColumnConfig<T = IKey> extends Omit<PartialVxeColumn, 'field'> {
  field?: keyof T
  slot?: keyof T
  show?: boolean
}

/**
 * 组件实例 获取导出的方法和属性
 */
type TableViewInstance = InstanceType<typeof TableView>
type VxeTableViewInstance = InstanceType<typeof VxeTableVue>

export { VxeTableVue, tableUtils, type IColumnConfig, type IVxueColumnConfig, type TableViewInstance, type VxeTableViewInstance, type IPropsFnObject }

/**
 * 默认导出为elemen-plus的table
 */
export default TableView
